<?php

function generateCode(int $length = 4): string
{
    $all_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ';
    $code = '';
    for ($i = 0; $i < $length; $i++) {
        $index = random_int(0, strlen($all_chars) - 1);
        $code .= $all_chars[$index];
    }
    return $code;
}

echo generateCode();
